//
//  MarriagePlanViewController.m
//  BaseProject
//
//  Created by mac on 2020/11/19.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "MarriagePlanViewController.h"
#import "MarriagePlanTableHeaderView.h"
#import "MarriagePlanModel.h"
#import "MarriagePlanSectionHeaderView.h"
#import "MarriagePlanCell.h"
#import <BRPickerView.h>
#import "MarriagePlanCreateTaskPopView.h"
#import "AnimRefreshHeader.h"
@interface MarriagePlanViewController ()<UITableViewDelegate,UITableViewDataSource,MarriagePlanCellDelegate,MarriagePlanSectionHeaderViewDelegate>
@property(nonatomic,strong)UITableView *mainView;
@property(nonatomic,strong)MarriagePlanTableHeaderView *tableHeaderView;
@property(nonatomic,strong)NSMutableArray<MarriagePlanSectionModel *> *dataSource;
@property(nonatomic,strong)MarriagePlanModel *planModel;
//时间选择器
@property(nonatomic,strong)BRDatePickerView *timePickerView;
@property(nonatomic,strong)UIButton *bottomButton;
//navi
@property(nonatomic,strong)UIView *naviBarView;//导航返回按钮
@property(nonatomic,strong)UIButton *naviBarBackButton;//导航底部视图
@property(nonatomic,strong)UILabel *naviBarTitleLab;//导航中间label
@property(nonatomic,strong)UIView *naviBarBottomLineView;//导航底部view
//包含导航
@property(nonatomic,assign)BOOL hasNaviBar;
//进入控制器时间
@property(nonatomic,strong)NSString *inTime;
@end

@implementation MarriagePlanViewController
- (void)dealloc
{
    NSLog(@"MarriagePlanViewController ---dealloc");
    [[StatisticManager shareManager]insertBrowseUserActiveQuantityWithToolType:@"2" WithInTime:self.inTime];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self createProperty];
    [self createUI];
    [self createNetManager];
    self.mainView.mj_header = [AnimRefreshHeader headerWithRefreshingTarget:self refreshingAction:@selector(createNetManager)];
    self.inTime = [NSString stringWithFormat:@"%0.0f",[Utilities getCurrentTimestamp]];
}
- (void)createProperty
{
    self.navigationController.navigationBarHidden = YES;
    #if RT_INTERACTIVE_PUSH
        self.rt_navigationController.rt_enableInteractivePush = YES;
    #endif
    self.rt_disableInteractivePop = NO;
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)createUI
{
    [self mainView];
    self.mainView.tableHeaderView = self.tableHeaderView;
    [self createNaviBarWithTitle:@"备婚计划"];
    [self bottomButton];
}
- (void)createNetManager
{
    WK(weakSelf)
    [SVProgressHUD showWithStatus:@"正在加载"];
    NSMutableDictionary *dic = @{}.mutableCopy;
    [dic setValue:[TTUserModel sharedObject].username forKey:@"userId"];
    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,@"/userMarryPlansOver/getUserMarryPlansOverList"];
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
        MarriagePlanModel *responModel = [MarriagePlanModel modelWithJSON:data];
        if (responModel.success) {
            weakSelf.planModel = responModel;
            [weakSelf handleData:responModel];
            [SVProgressHUD dismiss];
        } else {
            [SVProgressHUD showErrorWithStatus:responModel.message];
            [SVProgressHUD dismissWithDelay:1];
        }
        [weakSelf.mainView.mj_header endRefreshing];
    } FailedBlock:^(NSError * _Nonnull error) {
        [SVProgressHUD dismiss];
        [weakSelf.mainView.mj_header endRefreshing];
    }];
}
- (void)handleData:(MarriagePlanModel *)planModel
{
    NSMutableArray *array = [NSMutableArray array];
    for (NSInteger index = 0; index < 12; index ++) {
        MarriagePlanSectionModel *sectionModel = [[MarriagePlanSectionModel alloc]init];
        [array addObject:sectionModel];
        sectionModel.plansTime = [NSString stringWithFormat:@"%ld",index];
        sectionModel.flex = NO;
        if (index == 0) {
            sectionModel.plansTimeContent = @"我的任务";
            sectionModel.list = planModel.data.myTaskList;
        } else if (index == 1) {
            sectionModel.plansTimeContent = [NSString stringWithFormat:@"婚礼倒计时%@",@"9-12个月"];
            sectionModel.list = planModel.data.nineToTwelveList;
        } else if (index == 2) {
            sectionModel.plansTimeContent = [NSString stringWithFormat:@"婚礼倒计时%@",@"6-8个月"];
            sectionModel.list = planModel.data.sixToEightList;
        } else if (index == 3) {
            sectionModel.plansTimeContent = [NSString stringWithFormat:@"婚礼倒计时%@",@"3-5个月"];
            sectionModel.list = planModel.data.threeToFiveList;
        } else if (index == 4) {
            sectionModel.plansTimeContent = [NSString stringWithFormat:@"婚礼倒计时%@",@"1个月"];
            sectionModel.list = planModel.data.oneMonthList;
        } else if (index == 5) {
            sectionModel.plansTimeContent = [NSString stringWithFormat:@"婚礼倒计时%@",@"两周"];
            sectionModel.list = planModel.data.twoWeekList;
        } else if (index == 6) {
            sectionModel.plansTimeContent = [NSString stringWithFormat:@"婚礼倒计时%@",@"1周"];
            sectionModel.list = planModel.data.oneWeekList;
        } else if (index == 7) {
            sectionModel.plansTimeContent = [NSString stringWithFormat:@"婚礼倒计时%@",@"1天"];
            sectionModel.list = planModel.data.oneDayList;
        } else if (index == 8) {
            sectionModel.plansTimeContent = [NSString stringWithFormat:@"婚礼%@",@"当天"];
            sectionModel.list = planModel.data.toDayList;
        } else if (index == 9) {
            sectionModel.plansTimeContent = [NSString stringWithFormat:@"婚礼结束%@",@"第一天"];
            sectionModel.list = planModel.data.endOneDayList;
        } else if (index == 10) {
            sectionModel.plansTimeContent = [NSString stringWithFormat:@"婚礼结束%@",@"第二天"];
            sectionModel.list = planModel.data.endTwoDayList;
        } else if (index == 11) {
            sectionModel.plansTimeContent = [NSString stringWithFormat:@"婚礼结束%@",@"一个月"];
            sectionModel.list = planModel.data.endOneMonthList;
        }
        [self handleSectionModel:sectionModel];
        sectionModel.originList = sectionModel.list;
    }
    [self.dataSource removeAllObjects];
    [self.dataSource addObjectsFromArray:array.mutableCopy];
    [self.mainView reloadData];
    self.tableHeaderView.planModel = planModel;
}
- (void)handleSectionModel:(MarriagePlanSectionModel *)sectionModel
{
    NSInteger succeed = 0;
    for (NSInteger index = 0; index < sectionModel.list.count; index ++) {
        MarriagePlanDataListModel *listModel = sectionModel.list[index];
        [self handleListData:listModel];
        succeed += listModel.isSelected;
    }
    sectionModel.succeedNumber = succeed;
}
- (void)handleListData:(MarriagePlanDataListModel *)listModel
{
    {
        NSMutableAttributedString *titleAttributes = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",listModel.plansContent]];
        titleAttributes.font = kFontRegular14;
        titleAttributes.color = kColor51;
        listModel.plansContentNormal = titleAttributes;
    }
    
    {
        
        NSMutableAttributedString *titleAttributes = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",listModel.plansContent]];
        titleAttributes.font = kFontRegular14;
        titleAttributes.color = rgba(187, 187, 187, 1);
        [titleAttributes setStrikethroughStyle:NSUnderlineStyleSingle range:NSMakeRange(0, listModel.plansContent.length)];
        [titleAttributes setStrikethroughColor:rgba(204, 204, 204, 1)];
        [titleAttributes setBaselineOffset:@(NSUnderlineStyleSingle)];
        listModel.plansContentSelected = titleAttributes;
    }
    
    {
        //高度计算 52
        CGFloat titleWidth = 0.0f;
        if ([listModel.type isEqualToString:@"1"]) {
            if (listModel.overTime.length > 0) {
                titleWidth = 220*ADAPTER_WIDTH;
            } else {
                titleWidth = WIDTH - 58*ADAPTER_WIDTH;
                listModel.overTime = @"";
            }
        } else {
            titleWidth = WIDTH - 58*ADAPTER_WIDTH;
        }
        CGFloat titleHeight = [YYTextLayout layoutWithContainerSize:CGSizeMake(titleWidth, MAXFLOAT) text:listModel.plansContentSelected].textBoundingSize.height + 5*ADAPTER_WIDTH;
        //top 12 bottom 12
        listModel.titleWidth = titleWidth;
        listModel.titleHeight = titleHeight;
        listModel.cellHeight = titleHeight + 24*ADAPTER_WIDTH;
        
    }
    if ([listModel.status isEqualToString:@"1"]) {
        listModel.isSelected = NO;
    } else {
        listModel.isSelected = YES;
    }
    if (listModel.overTime.length > 10) {
        listModel.overTime = [listModel.overTime substringToIndex:10];
    }
}
#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataSource.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSource[section].flex ? self.dataSource[section].list.count : 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MarriagePlanCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.listModel = self.dataSource[indexPath.section].list[indexPath.row];
    cell.indexPath = indexPath;
    cell.delegate = self;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return self.dataSource[indexPath.section].list[indexPath.row].cellHeight;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    MarriagePlanSectionHeaderView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"sectionHeader"];
    view.sectionModel = self.dataSource[section];
    view.delegate = self;
    view.section = section;
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 60*ADAPTER_WIDTH;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UITableViewHeaderFooterView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"sectionFooter"];
    view.contentView.backgroundColor = WhiteColor;
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return self.dataSource[section].flex ? 10*ADAPTER_WIDTH : 0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MarriagePlanDataListModel *listModel = self.dataSource[indexPath.section].list[indexPath.row];
    if ([listModel.type isEqualToString:@"1"]) {
        [self clickRightButton:listModel];
    }
}
#pragma mark - sectionHeader代理
- (void)marriagePlanSectionHeaderViewBackType:(NSInteger)type backSection:(NSInteger)section
{
    MarriagePlanSectionModel *sectionModel = self.dataSource[section];
    sectionModel.flex = !sectionModel.flex;
    [self.mainView reloadSection:section withRowAnimation:UITableViewRowAnimationNone];
    dispatch_async(dispatch_get_main_queue(), ^{
        if (!sectionModel.flex) {
            return;
        }
        MarriagePlanSectionHeaderView *view = (MarriagePlanSectionHeaderView *)[self.mainView headerViewForSection:section];
        if (!view) {
            return;
        }
        CGFloat totalHeight = 60*ADAPTER_WIDTH;
        for (NSInteger index = 0; index < view.sectionModel.list.count; index ++) {
            totalHeight += view.sectionModel.list[index].cellHeight;
        }
        CGFloat topY = view.top - self.mainView.contentOffset.y;
        CGFloat visibleHeight = self.mainView.height;
        if ((totalHeight + topY + (self.hasNaviBar ? kTopHeight : 0)) > visibleHeight) {
            //反推topY
            topY = self.mainView.height - totalHeight - (self.hasNaviBar ? kTopHeight : 0);
            if (topY < 0) {
                topY = 0;
            }
            CGFloat contentOffsetY = view.top - topY - kTopHeight;
            [self.mainView setContentOffset:CGPointMake(0, contentOffsetY) animated:YES];
        }
    });
}
#pragma mark - Cell代理
- (void)MarriagePlanCellBackType:(NSInteger)type backIndexPath:(NSIndexPath *)indexPath
{
    WK(weakSelf)
    MarriagePlanDataListModel *listModel = self.dataSource[indexPath.section].list[indexPath.row];
    NSMutableDictionary *dic = @{}.mutableCopy;
    [dic setValue:listModel.umpoId forKey:@"umpoId"];
    [dic setValue:listModel.isSelected?@"1":@"2" forKey:@"status"];
    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,@"/userMarryPlansOver/updateUserMarryPlansOver"];
    [SVProgressHUD showWithStatus:@"正在加载"];
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
        NSLog(@"%@",data);
        BaseResponse *responModel = [BaseResponse modelWithJSON:data];
        if (responModel.success) {
            listModel.isSelected = !listModel.isSelected;
            if ([listModel.status isEqualToString:@"2"]) {
                listModel.status = @"1";
            } else {
                listModel.status = @"2";
            }
            //处理数据
            NSInteger marryOverTaskTotal = 0,marryTaskTotal = 0;
            for (NSInteger index = 0; index < weakSelf.dataSource.count; index ++) {
                MarriagePlanSectionModel *sectionModel = weakSelf.dataSource[index];
                NSInteger succeed = 0;
                for (NSInteger flag = 0; flag < sectionModel.originList.count; flag ++) {
                    MarriagePlanDataListModel *listModel = sectionModel.originList[flag];
                    marryTaskTotal += 1;
                    marryOverTaskTotal += listModel.isSelected;
                    succeed += listModel.isSelected;
                }
                sectionModel.succeedNumber = succeed;
            }
            weakSelf.planModel.data.marryOverTaskTotal = marryOverTaskTotal;
            weakSelf.planModel.data.marryTaskTotal = marryTaskTotal;
            weakSelf.tableHeaderView.planModel = weakSelf.planModel;
            //处理数据
            //[weakSelf.mainView reloadRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationAutomatic];
            [weakSelf.mainView reloadSection:indexPath.section withRowAnimation:UITableViewRowAnimationAutomatic];
            [SVProgressHUD dismiss];
        } else {
            [SVProgressHUD dismiss];
        }
    } FailedBlock:^(NSError * _Nonnull error) {
        [SVProgressHUD dismiss];
    }];
}
#pragma mark - UITableView编辑模块
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return YES;
    }
    return NO;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WK(weakSelf)
    UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        NSLog(@"删除");
        [weakSelf deleteTaskIndexPath:indexPath];
    }];
    deleteAction.backgroundColor = rgba(253, 122, 189, 1);
    UITableViewRowAction *cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"取消" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        NSLog(@"取消");
    }];
    cancelAction.backgroundColor = rgba(152, 152, 152, 1);
    return @[deleteAction,cancelAction];
}
- (void)deleteTaskIndexPath:(NSIndexPath *)indexPath
{
    WK(weakSelf)
    MarriagePlanDataListModel *listModel = self.dataSource[indexPath.section].list[indexPath.row];
    NSMutableDictionary *dic = @{}.mutableCopy;
    [dic setValue:listModel.umpoId forKey:@"umpoId"];
    [dic setValue:@"1" forKey:@"isDel"];
    [dic setValue:listModel.isSelected?@"2":@"1" forKey:@"status"];
    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,@"/userMarryPlansOver/updateUserMarryPlansOver"];
    [SVProgressHUD showWithStatus:@"正在加载"];
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
        NSLog(@"%@",data);
        BaseResponse *responModel = [BaseResponse modelWithJSON:data];
        if (responModel.success) {
            //删除数据
            [weakSelf.dataSource[indexPath.section].list removeObject:listModel];
            [weakSelf.dataSource[indexPath.section].originList removeObject:listModel];
            //处理数据
            NSInteger marryOverTaskTotal = 0,marryTaskTotal = 0;
            for (NSInteger index = 0; index < weakSelf.dataSource.count; index ++) {
                MarriagePlanSectionModel *sectionModel = weakSelf.dataSource[index];
                NSInteger succeed = 0;
                for (NSInteger flag = 0; flag < sectionModel.originList.count; flag ++) {
                    MarriagePlanDataListModel *listModel = sectionModel.originList[flag];
                    marryTaskTotal += 1;
                    marryOverTaskTotal += listModel.isSelected;
                    succeed += listModel.isSelected;
                }
                sectionModel.succeedNumber = succeed;
            }
            weakSelf.planModel.data.marryOverTaskTotal = marryOverTaskTotal;
            weakSelf.planModel.data.marryTaskTotal = marryTaskTotal;
            weakSelf.tableHeaderView.planModel = weakSelf.planModel;
            //处理数据
            //[weakSelf.mainView reloadRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationAutomatic];
            [weakSelf.mainView reloadSection:indexPath.section withRowAnimation:UITableViewRowAnimationAutomatic];
            [SVProgressHUD dismiss];
        } else {
            [SVProgressHUD dismiss];
        }
    } FailedBlock:^(NSError * _Nonnull error) {
        [SVProgressHUD dismiss];
    }];
}
#pragma mark - click
- (void)clickRightButton:(MarriagePlanDataListModel *)listModel
{
    MarriagePlanCreateTaskPopView *view = [[MarriagePlanCreateTaskPopView alloc]initWithFrame:CGRectMake(0, 0, 305*ADAPTER_WIDTH, 280*ADAPTER_WIDTH) popStyle:ZJAnimationPopStyleShakeFromTop dismissStyle:ZJAnimationDismissStyleDropToBottom parentView:self.view];
    if (listModel != nil) {
        view.listModel = listModel;
    }
    WK(weakSelf)
    [view setRefreshBlock:^{
        [weakSelf createNetManager];
    }];
    [view setUpdateBlock:^(MarriagePlanDataListModel * _Nonnull listModel) {
        [weakSelf handleListData:listModel];
        [weakSelf.mainView reloadData];
    }];
    
}
- (void)clickEidteButton:sender
{
    [self.timePickerView show];
}
- (void)clickBottomButton:(UIButton *)sender
{
    sender.selected = !sender.selected;
    for (NSInteger index = 0; index < self.dataSource.count; index ++) {
        MarriagePlanSectionModel *sectionModel = self.dataSource[index];
        NSMutableArray *list = [NSMutableArray array];
        for (NSInteger flag = 0; flag < sectionModel.originList.count; flag ++) {
            if (sender.selected) {
                if ([sectionModel.originList[flag].status isEqualToString:@"1"]) {
                    [list addObject:sectionModel.originList[flag]];
                }
            } else {
                [list addObject:sectionModel.originList[flag]];
            }
        }
        sectionModel.list = list;
    }
    [self.mainView reloadData];
}
#pragma mark - lazy懒加载
- (UITableView *)mainView
{
    if (!_mainView) {
        UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - kBottomSafeHeight - 50*ADAPTER_WIDTH) style:UITableViewStylePlain];
        [self.view addSubview:tableView];
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.tableFooterView = [UIView new];
        [tableView registerClass:[MarriagePlanCell class] forCellReuseIdentifier:@"Cell"];
        [tableView registerClass:[MarriagePlanSectionHeaderView class] forHeaderFooterViewReuseIdentifier:@"sectionHeader"];
        [tableView registerClass:[UITableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"sectionFooter"];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView.backgroundColor = [UIColor whiteColor];
        if (@available(iOS 11.0, *))
        {
            tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            tableView.estimatedRowHeight = 0;
            tableView.estimatedSectionFooterHeight = 0;
            tableView.estimatedSectionHeaderHeight = 0;
        }
        else
        {
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
        _mainView = tableView;
    }
    return _mainView;
}
- (MarriagePlanTableHeaderView *)tableHeaderView
{
    if (!_tableHeaderView) {
        MarriagePlanTableHeaderView *view = [[MarriagePlanTableHeaderView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, kStatusBarHeight + 210*ADAPTER_WIDTH)];
        WK(weakSelf)
        [view setClickEditeButtonBlock:^{
            [weakSelf clickEidteButton:nil];
        }];
        [view setClickTaskButtonBlock:^{
            [weakSelf clickRightButton:nil];
        }];
        _tableHeaderView = view;
    }
    return _tableHeaderView;
}
- (NSMutableArray<MarriagePlanSectionModel *> *)dataSource
{
    if (!_dataSource) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}

- (BRDatePickerView *)timePickerView
{
    if (!_timePickerView) {
        BRDatePickerView *view = [[BRDatePickerView alloc]init];
        // 2.设置属性
        view.pickerMode = BRDatePickerModeYMD;
        view.title = @"选择年月日";
        view.minDate = [Utilities getDateWithTimestamp:[Utilities getCurrentTimestamp]];
        view.maxDate = [NSDate br_setYear:2050 month:12 day:1];
        //view.isAutoSelect = YES;
        view.showToday = YES;
        WK(weakSelf)
        //marryTime
        [view setResultBlock:^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
            NSMutableDictionary *dic = @{}.mutableCopy;
            [dic setValue:selectValue forKey:@"marryTime"];
            [dic setValue:[TTUserModel sharedObject].userId forKey:@"userId"];
            NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_EditMyInfo];
            [SVProgressHUD showWithStatus:@"正在加载"];
            [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
                NSLog(@"%@",data);
                BaseResponse *responModel = [BaseResponse modelWithJSON:data];
                if (responModel.success) {
                    [weakSelf.tableHeaderView updateWithNewTime:selectValue];
                    [SVProgressHUD dismiss];
                } else {
                    [SVProgressHUD showWithStatus:responModel.message];
                    [SVProgressHUD dismissWithDelay:1];
                }
            } FailedBlock:^(NSError * _Nonnull error) {
                [SVProgressHUD dismiss];
            }];
        }];
        _timePickerView = view;
    }
    return _timePickerView;
}
- (UIButton *)bottomButton
{
    if (!_bottomButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.view addSubview:button];
        [button setTitle:@"隐藏已经完成内容" forState:UIControlStateNormal];
        [button setTitle:@"展开已经完成内容" forState:UIControlStateSelected];
        [button setTitleColor:WhiteColor forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:16*ADAPTER_WIDTH weight:UIFontWeightRegular];
        [button addTarget:self action:@selector(clickBottomButton:) forControlEvents:UIControlEventTouchUpInside];
        button.frame = CGRectMake(0, HEIGHT - 50*ADAPTER_WIDTH - kBottomSafeHeight, WIDTH, 50*ADAPTER_WIDTH);
        button.backgroundColor = rgba(253, 122, 189, 1);
        _bottomButton = button;
    }
    return _bottomButton;
}
#pragma mark - Navi
- (void)clickNaviBarBackButton:sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (UIView *)createNaviBarWithTitle:(NSString *)title
{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, kTopHeight)];
    view.backgroundColor = WhiteColor;
    [self.view addSubview:view];
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [view addSubview:backButton];
    [backButton setImage:[UIImage imageNamed:@"public_back_white"] forState:UIControlStateNormal];
    backButton.frame = CGRectMake(0, kStatusBarHeight, 20 + 32, kNavBarHeight);//20x20
    CGFloat top = (kNavBarHeight - 20) * 0.5;
    backButton.imageEdgeInsets = UIEdgeInsetsMake(top, 16, top, 16);
    [backButton addTarget:self action:@selector(clickNaviBarBackButton:) forControlEvents:UIControlEventTouchUpInside];

    UILabel *titleLab = [[UILabel alloc]init];
    [view addSubview:titleLab];
    titleLab.font = kFontBold(18);
    titleLab.textColor = kColor51;
    titleLab.textAlignment = NSTextAlignmentCenter;
    titleLab.text = title;
    titleLab.frame = CGRectMake(50, kStatusBarHeight, WIDTH - 100, 19);
    titleLab.centerY = backButton.centerY;

    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, view.height - kLineHeight, view.width, kLineHeight)];
    [view addSubview:lineView];
    lineView.backgroundColor = kLineColor;
    
    
    view.backgroundColor = ClearColor;
    lineView.backgroundColor = ClearColor;
    titleLab.textColor = WhiteColor;
    
    self.naviBarView = view;
    self.naviBarTitleLab = titleLab;
    self.naviBarBackButton = backButton;
    self.naviBarBottomLineView = lineView;
    return view;
}
#pragma mark - ScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat percent = scrollView.contentOffset.y / kTopHeight;
    if (percent > 1.0) {
        percent = 1.0;
    }
    if (percent > 0.25) {
        self.naviBarTitleLab.textColor = kColor51;
        [self.naviBarBackButton setImage:[UIImage imageNamed:@"public_back_black"] forState:UIControlStateNormal];
        self.naviBarBottomLineView.backgroundColor = kLineColor;
        self.hasNaviBar = NO;
    } else {
        self.naviBarTitleLab.textColor = WhiteColor;
        [self.naviBarBackButton setImage:[UIImage imageNamed:@"public_back_white"] forState:UIControlStateNormal];
        self.naviBarBottomLineView.backgroundColor = ClearColor;
        self.hasNaviBar = YES;
    }
    self.naviBarView.backgroundColor = rgba(255, 255, 255, percent);
}
@end

